<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="180px">
      <el-form-item label="生产线代码" prop="lineCode">
        <el-input
          v-model="queryParams.lineCode"
          placeholder="请输入生产线代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产线名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入生产线名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工位代码" prop="gwCode">
        <el-input
          v-model="queryParams.gwCode"
          placeholder="请输入工位代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工位名称" prop="gwName">
        <el-input
          v-model="queryParams.gwName"
          placeholder="请输入工位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="转换节点" prop="jdzh">
        <el-input
          v-model="queryParams.jdzh"
          placeholder="请输入转换节点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="节点操作工号" prop="jdEmpNum">
        <el-input
          v-model="queryParams.jdEmpNum"
          placeholder="请输入节点操作工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点人姓名" prop="jdEmpName">
        <el-input
          v-model="queryParams.jdEmpName"
          placeholder="请输入节点人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点转换前物料分类" prop="jdzhqItemClass">
        <el-input
          v-model="queryParams.jdzhqItemClass"
          placeholder="请输入节点转换前物料分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点转换前物料号简码" prop="jdzhqItemId">
        <el-input
          v-model="queryParams.jdzhqItemId"
          placeholder="请输入节点转换前物料号简码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点转换前物料名称" prop="jdzhqItemName">
        <el-input
          v-model="queryParams.jdzhqItemName"
          placeholder="请输入节点转换前物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="转换前质量状态" prop="jdzhqQualityState">
        <el-input
          v-model="queryParams.jdzhqQualityState"
          placeholder="请输入转换前质量状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="节点转换后物料分类" prop="jdzhhItemClass">
        <el-input
          v-model="queryParams.jdzhhItemClass"
          placeholder="请输入节点转换后物料分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点转换后物料号简码" prop="jdzhhItemId">
        <el-input
          v-model="queryParams.jdzhhItemId"
          placeholder="请输入节点转换后物料号简码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点转换后物料名称" prop="jdzhhItemName">
        <el-input
          v-model="queryParams.jdzhhItemName"
          placeholder="请输入节点转换后物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="转换后质量状态" prop="jdzhhQualityState">
        <el-input
          v-model="queryParams.jdzhhQualityState"
          placeholder="请输入转换后质量状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="仓库编码" prop="stockId">
        <el-input
          v-model="queryParams.stockId"
          placeholder="请输入仓库编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库名称" prop="stockName">
        <el-input
          v-model="queryParams.stockName"
          placeholder="请输入仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位编码" prop="kuweiCode">
        <el-input
          v-model="queryParams.kuweiCode"
          placeholder="请输入库位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['base:iteminfoJs:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:iteminfoJs:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:iteminfoJs:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['base:iteminfoJs:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="iteminfoJsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="生产线代码" width="130" show-overflow-tooltip align="center" prop="lineCode" />
      <el-table-column label="生产线名称" width="130" show-overflow-tooltip align="center" prop="lineName" />
      <el-table-column label="工位代码" width="130" show-overflow-tooltip align="center" prop="gwCode" />
      <el-table-column label="工位名称" width="130" show-overflow-tooltip align="center" prop="gwName" />
      <el-table-column label="转换节点" width="130" show-overflow-tooltip  align="center" prop="jdzh" />
      <el-table-column label="节点操作工号" width="130" show-overflow-tooltip align="center" prop="jdEmpNum" />
      <el-table-column label="节点人姓名" width="120" show-overflow-tooltip align="center" prop="jdEmpName" />
      <el-table-column label="节点转换前物料分类" align="center" prop="jdzhqItemClass" />
      <el-table-column label="节点转换前物料号简码" width="130" show-overflow-tooltip align="center" prop="jdzhqItemId" />
<!--
      <el-table-column label="节点转换前物料名称" width="130" show-overflow-tooltip align="center" prop="jdzhqItemName" />
-->
      <el-table-column label="转换前质量状态" align="center" prop="jdzhqQualityState" />
      <el-table-column label="节点转换后物料分类" align="center" prop="jdzhhItemClass" />
      <el-table-column label="节点转换后物料号简码" width="130" show-overflow-tooltip align="center" prop="jdzhhItemId" />
<!--
      <el-table-column label="节点转换后物料名称" width="130" show-overflow-tooltip align="center" prop="jdzhhItemName" />
-->
      <el-table-column label="转换后质量状态" align="center" prop="jdzhhQualityState" />
      <el-table-column label="仓库编码" width="130" show-overflow-tooltip  align="center" prop="stockId" />
<!--
      <el-table-column label="仓库名称" width="130" show-overflow-tooltip align="center" prop="stockName" />
-->
      <el-table-column label="库位编码" width="130" show-overflow-tooltip align="center" prop="kuweiCode" />
      <el-table-column label="入库方式" width="130" show-overflow-tooltip align="center" prop="rukuType" />
      <el-table-column label="出库方式" width="130" show-overflow-tooltip align="center" prop="chukuType" />
      <el-table-column label="备注"  show-overflow-tooltip align="center" prop="remark" />
      <el-table-column label="操作" width="120" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:iteminfoJs:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:iteminfoJs:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改物料号转换计算对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司代码" prop="factoryCode">
          <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="factoryName">
          <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="生产线代码" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入生产线代码" />
        </el-form-item>
        <el-form-item label="生产线名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入生产线名称" />
        </el-form-item>
        <el-form-item label="工位代码" prop="gwCode">
          <el-input v-model="form.gwCode" placeholder="请输入工位代码" />
        </el-form-item>
        <el-form-item label="工位名称" prop="gwName">
          <el-input v-model="form.gwName" placeholder="请输入工位名称" />
        </el-form-item>
        <el-form-item label="转换节点" prop="jdzh">
          <el-input v-model="form.jdzh" placeholder="请输入转换节点" />
        </el-form-item>
        <el-form-item label="节点操作工号" prop="jdEmpNum">
          <el-input v-model="form.jdEmpNum" placeholder="请输入节点操作工号" />
        </el-form-item>
        <el-form-item label="节点人姓名" prop="jdEmpName">
          <el-input v-model="form.jdEmpName" placeholder="请输入节点人姓名" />
        </el-form-item>
        <el-form-item label="节点转换前物料分类" prop="jdzhqItemClass">
          <el-input v-model="form.jdzhqItemClass" placeholder="请输入节点转换前物料分类" />
        </el-form-item>
        <el-form-item label="节点转换前物料号简码" prop="jdzhqItemId">
          <el-input v-model="form.jdzhqItemId" placeholder="请输入节点转换前物料号简码" />
        </el-form-item>
        <el-form-item label="节点转换前物料名称" prop="jdzhqItemName">
          <el-input v-model="form.jdzhqItemName" placeholder="请输入节点转换前物料名称" />
        </el-form-item>
        <el-form-item label="转换前质量状态" prop="jdzhqQualityState">
          <el-input v-model="form.jdzhqQualityState" placeholder="请输入转换前质量状态" />
        </el-form-item>
        <el-form-item label="节点转换后物料分类" prop="jdzhhItemClass">
          <el-input v-model="form.jdzhhItemClass" placeholder="请输入节点转换后物料分类" />
        </el-form-item>
        <el-form-item label="节点转换后物料号简码" prop="jdzhhItemId">
          <el-input v-model="form.jdzhhItemId" placeholder="请输入节点转换后物料号简码" />
        </el-form-item>
        <el-form-item label="节点转换后物料名称" prop="jdzhhItemName">
          <el-input v-model="form.jdzhhItemName" placeholder="请输入节点转换后物料名称" />
        </el-form-item>
        <el-form-item label="转换后质量状态" prop="jdzhhQualityState">
          <el-input v-model="form.jdzhhQualityState" placeholder="请输入转换后质量状态" />
        </el-form-item>
        <el-form-item label="仓库编码" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入仓库编码" />
        </el-form-item>
        <el-form-item label="仓库名称" prop="stockName">
          <el-input v-model="form.stockName" placeholder="请输入仓库名称" />
        </el-form-item>
        <el-form-item label="库位编码" prop="kuweiCode">
          <el-input v-model="form.kuweiCode" placeholder="请输入库位编码" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listIteminfoJs, getIteminfoJs, delIteminfoJs, addIteminfoJs, updateIteminfoJs } from "@/api/base/iteminfoJs";

export default {
  name: "IteminfoJs",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料号转换计算表格数据
      iteminfoJsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lineCode: null,
        lineName: null,
        gwCode: null,
        gwName: null,
        jdzh: null,
        jdEmpNum: null,
        jdEmpName: null,
        jdzhqItemClass: null,
        jdzhqItemId: null,
        jdzhqItemName: null,
        jdzhqQualityState: null,
        jdzhhItemClass: null,
        jdzhhItemId: null,
        jdzhhItemName: null,
        jdzhhQualityState: null,
        stockId: null,
        stockName: null,
        kuweiCode: null,
        rukuType: null,
        chukuType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物料号转换计算列表 */
    getList() {
      this.loading = true;
      listIteminfoJs(this.queryParams).then(response => {
        this.iteminfoJsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        factoryName: null,
        lineCode: null,
        lineName: null,
        gwCode: null,
        gwName: null,
        jdzh: null,
        jdEmpNum: null,
        jdEmpName: null,
        userId: null,
        jdzhqItemClass: null,
        jdzhqItemId: null,
        jdzhqItemName: null,
        jdzhqQualityState: null,
        jdzhhItemClass: null,
        jdzhhItemId: null,
        jdzhhItemName: null,
        jdzhhQualityState: null,
        stockId: null,
        stockName: null,
        kuweiCode: null,
        rukuType: null,
        chukuType: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加物料号转换计算";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getIteminfoJs(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改物料号转换计算";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateIteminfoJs(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addIteminfoJs(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除物料号转换计算编号为"' + ids + '"的数据项？').then(function() {
        return delIteminfoJs(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('base/iteminfoJs/export', {
        ...this.queryParams
      }, `iteminfoJs_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
